#include <iostream>
using namespace std;
class Test
{
 public:
 int *p;
 Test(Test &&t) //移动构造函数，***注意此处传入参数是右值引用
 {
     p = t.p;
     t.p = nullptr;//将临时对象的指针赋值为空
     cout<<" move construct"<<endl;
 }
 Test(const Test &t) //拷贝构造函数
 {
     p = new int (*(t.p));
     cout<<" copy construct"<<endl;
 }
  Test(){ p=new int(18); cout<<"construct"<<endl; };
  ~Test(){ delete p; cout<<"disconstruct"<<endl; };
  void show()const{
	   cout<<*p<<endl;
  }
};
Test getT(){
	return Test();
}
int main(void)
{

        Test t1(getT());
		t1.show();
    
	return 0;
}
//告诉编译器不要优化，需要看过程：-fno-elide-constructors
//g++ -std=c++11 -fno-elide-constructors  move_constructor_test.cpp -o move_constructor_test.out

//某次打印
/**
construct
 move construct
disconstruct
 move construct
disconstruct
18
disconstruct
**/